const getCountDownTime = (orderTime, delayMinutes = 30, type) => { // 2020-11-08 20:11:00
	let a = orderTime.split(' ')[0].split('-')
	let b = orderTime.split(' ')[1].split(':')
	const d = (new Date(a[0], a[1] - 1, a[2], b[0], b[1], b[2])).valueOf()

	let str = ''
	const oDate = new Date(); //获取日期对象
	const oldTime = oDate.getTime(); //现在距离1970年的毫秒数
	const newTime = d + delayMinutes * 60 * 1000;
	let second = Math.floor((newTime - oldTime) / 1000); //未来时间距离现在的秒数
	if (second <= 0) return false
	let day = Math.floor(second / 86400); //整数部分代表的是天；一天有24*60*60=86400秒 ；
	second = second % 86400; //余数代表剩下的秒数；
	let hour = Math.floor(second / 3600); //整数部分代表小时；
	second %= 3600; //余数代表 剩下的秒数；
	let minute = Math.floor(second / 60);
	second %= 60;
	if (type) { // 如果有type　返回时分秒　小时可以超过24 没有天
		hour = hour + day * 24
		str = tow(hour) + ':' + tow(minute) + ':' + tow(second)
	} else {
		str = tow(minute) + ':' + tow(second)
	}

	function tow(n) {
		return n >= 0 && n < 10 ? '0' + n : '' + n;
	}
	return str
}

const getHourTime = (startTime, endTime) => {
	let a = startTime.split(' ')[0].split('-')
	let b = startTime.split(' ')[1].split(':')
	let m = endTime.split(' ')[0].split('-')
	let n = endTime.split(' ')[1].split(':')
	const d = (new Date(a[0], a[1] - 1, a[2], b[0], b[1], b[2])).valueOf()
	const p = (new Date(m[0], m[1] - 1, m[2], n[0], n[1], n[2])).valueOf()
	let second = (p - d) / 1000; //未来时间距离现在的秒数
	if (second <= 0) return false
	let hour = second / 3600
	return hour
}

const getWeekByDate = (date = new Date()) => {
	const d = new Date(date.replace(/-/g, '/'))
	const i = d.getDay()
	let w = ''
	switch (i) {
		case 0:
			w = '周日'
			break
		case 1:
			w = '周一'
			break
		case 2:
			w = '周二'
			break
		case 3:
			w = '周三'
			break
		case 4:
			w = '周四'
			break
		case 5:
			w = '周五'
			break
		case 6:
			w = '周六'
			break
	}
	return w
}
const employStarHidden = (str, frontLen, endLen) => { //str：要进行隐藏的变量  frontLen: 前面需要保留几位    endLen: 后面需要保留几位
	var len = str.length - frontLen - endLen;
	var xing = '';
	for (var i = 0; i < len; i++) {
		xing += '*';
	}
	return str.substring(0, frontLen) + xing + str.substring(str.length - endLen);
}




export default {
	getCountDownTime,
	getHourTime,
	getWeekByDate,
	employStarHidden
}
